<?php
/**
 *  NevuxBB - Free Forum Software
 *  Copyright (C) 2008, 2010 NevuxBB (No one specific author)*  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Settings File
 * File: settings.php
 * Purpose: For getting settings from the database for the board
 * Todo: Improve the structure of this file
 *
 */

// connect to the database -- change the mysql connection info
// in the file config.php not here!! --
Db_Abstraction::connect(array('dbhost' => $config['db_host'],
							  'dbuser' => $config['db_user'],
							  'dbpass' => $config['db_pass'],
							  'dbname' => $config['db_name']));


// create a "global" class with a "global variable"
class GlobalSettings {
	static $global_settings_data;
	
	public static function generateSettings() {
		// begin to retrieve and set all the settings
		// retrieve the forums settings
		$db_settings = Db_Abstraction::query('SELECT * FROM `nbb_settings` WHERE `settings_area` = 0');
		
		// main board settings
		$config = array();
		
		while($row = DB_Abstraction::fetch_assoc($db_settings)) {
			self::$global_settings_data[$row['settings_name']] = array('data' => $row['settings_data']);
		}
	}
	
	public static function getSetting($name, $array=NULL) {
		// is array set? (should we output an array?)
		if($array === NULL) {
			// don't output an array, only ['data']
			return self::$global_settings_data[$name]['data'];
		} else {
			// output the whole array
			return self::$global_settings_data[$name];
		}
	}
}

// begin to generate now
GlobalSettings::generateSettings();
?>